<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/1/22
 * Time: 20:59
 */

namespace app\storage\model;


use think\Db;
use think\Model;

class CarModel extends Model
{
    protected $table = 'iwh_car';

    public function getCar($condition){
        $where = $condition['where'];
        $pageIndex = $condition['pageIndex'];
        $pageSize = $condition['pageSize'];
        $ret['total'] = $this->where($where)->count();
        $ret['row'] = $this->where($where)->page($pageIndex,$pageSize)->order('car_id asc')->select();
        return $ret;
    }

    public function deleteCar($uuid){
        Db::startTrans();
        $shelfTran = Db::table('iwh_car')->where(['uuid' => $uuid])->delete();
        $seatTran = Db::table('iwh_car_seat')->where(['car_uuid' => $uuid])->delete();
        if ($shelfTran == true && $seatTran !== false) {
            Db::commit();
            return true;
        } else {
            Db::rollback();
            return false;
        }
    }

}